package com.ttg.web.controller.common;

import com.ttg.common.entities.BaseResult;
import com.ttg.common.utils.RequestParamsManager;
import com.ttg.model.dto.*;
import com.ttg.web.service.ConditionsNameService;
import com.ttg.web.service.TagInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * @author zhangjie
 * @date 2021/3/16 14:38
 */
@Slf4j
@Api("标签模块")
@RestController
@RequestMapping("/tag")
public class TagController {
    @Autowired
    private TagInfoService tagInfoService;

    @Autowired
    private ConditionsNameService conditionsNameService;

    @ApiOperation("获取条件列表-delete")
    @RequestMapping("/condition/list")
    public BaseResult conditionList(@RequestBody(required = false) String data){
        return BaseResult.success(conditionsNameService.conditionList());
    }

    @ApiOperation("获取标签分页")
    @RequestMapping("/page")
    public BaseResult tagPage(@RequestBody(required = false) String data){
        TagPageDTO reqDto = RequestParamsManager.transformRequestParam(data, TagPageDTO.class);
        return BaseResult.success(tagInfoService.tagPage(reqDto));
    }

    @ApiOperation("标签添加")
    @RequestMapping("/add")
    public BaseResult tagAdd(@RequestBody(required = false) String data){
        TagInfoDTO reqDto = RequestParamsManager.transformRequestParam(data, TagInfoDTO.class);
        return tagInfoService.tagAdd(reqDto);
    }

    @ApiOperation("编辑标签预览")
    @RequestMapping("/info")
    public BaseResult tagInfo(@RequestBody(required = false) String data){
        TagPageDTO reqDto = RequestParamsManager.transformRequestParam(data, TagPageDTO.class);
        return BaseResult.success(tagInfoService.tagInfo(reqDto));
    }

    @ApiOperation("标签编辑")
    @RequestMapping("/update")
    public BaseResult tagUpdate(@RequestBody(required = false) String data){
        TagInfoDTO reqDto = RequestParamsManager.transformRequestParam(data, TagInfoDTO.class);
        return tagInfoService.tagUpdate(reqDto);
    }

    @ApiOperation("标签状态修改 bj")
    @RequestMapping("/updateStatus")
    public BaseResult updateStatus(@RequestBody(required = false) String data){
        TagPageDTO reqDto = RequestParamsManager.transformRequestParam(data, TagPageDTO.class);
        return BaseResult.success(tagInfoService.tagUpdateStatus(reqDto));
    }

    @ApiOperation("标签导出")
    @RequestMapping("/export")
    public void export(@RequestBody(required = false) String data, HttpServletResponse response){
        TagPageDTO reqDto = RequestParamsManager.transformRequestParam(data, TagPageDTO.class);
        tagInfoService.export(reqDto, response);
    }

    @ApiOperation("获取标签会员分页")
    @RequestMapping("/vip/page")
    public BaseResult tagVipPage(@RequestBody(required = false) String data){
        TagVipPageDTO reqDto = RequestParamsManager.transformRequestParam(data, TagVipPageDTO.class);
        return BaseResult.success(tagInfoService.tagVipPage(reqDto));
    }

    @ApiOperation("获取标签会员分页")
    @RequestMapping("/vip/page/export")
    public void tagVipPageExport(@RequestBody(required = false) String data, HttpServletResponse response){
        TagVipPageDTO reqDto = RequestParamsManager.transformRequestParam(data, TagVipPageDTO.class);
        tagInfoService.tagVipPageExport(reqDto,response);
    }



    @ApiOperation("获取商户标签分页")
    @RequestMapping("/mct/page")
    public BaseResult tagMctPage(@RequestBody(required = false) String data){
        TagMctPageDTO reqDto = RequestParamsManager.transformRequestParam(data, TagMctPageDTO.class);
        return BaseResult.success(tagInfoService.tagMctPage(reqDto));
    }

    @ApiOperation("获取标签商户分页")
    @RequestMapping("/mct/tagPage")
    public BaseResult mctTagPage(@RequestBody(required = false) String data){
        MctTagPageDto reqDto = RequestParamsManager.transformRequestParam(data, MctTagPageDto.class);
        return BaseResult.success(tagInfoService.mctTagPage(reqDto));
    }


    @ApiOperation("标签商户导出")
    @RequestMapping("/mct/tagPage/export")
    public void mctTagPageExport(@RequestBody(required = false) String data, HttpServletResponse response){
        MctTagPageDto reqDto = RequestParamsManager.transformRequestParam(data, MctTagPageDto.class);
        tagInfoService.mctTagPageExport(reqDto, response);
    }

    @ApiOperation("获取标签分页")
    @RequestMapping("/page/vip")
    public BaseResult tagPageByVip(@RequestBody(required = false) String data){
        TagVipPageDTO reqDto = RequestParamsManager.transformRequestParam(data, TagVipPageDTO.class);
        return BaseResult.success(tagInfoService.tagPageByVip(reqDto));
    }



    @ApiOperation("获取标签分类 bj")
    @RequestMapping("/getConditionClass")
    public BaseResult getConditionClassByStatus(@RequestBody(required = false) String data){
        GetConditionClassByStatusDto reqDto = RequestParamsManager.transformRequestParam(data, GetConditionClassByStatusDto.class);
        return BaseResult.success(conditionsNameService.getAllByStatus(reqDto));
    }

    @ApiOperation("根据标签分类获取标签条件 bj")
    @RequestMapping("/getConditionNameByClass")
    public BaseResult getConditionNameByClass(@RequestBody(required = false) String data){
        GetConditionNameByClassDto reqDto = RequestParamsManager.transformRequestParam(data, GetConditionNameByClassDto.class);
        return BaseResult.success(conditionsNameService.getConditionNameByClass(reqDto));
    }


    @ApiOperation("单个标签更新")
    @RequestMapping("/update/tagBind")
    public BaseResult updateTagBind(@RequestBody(required = false) String data){
        TagBindDto reqDto = RequestParamsManager.transformRequestParam(data, TagBindDto.class);
        return BaseResult.success(tagInfoService.updateTagBind(reqDto));
    }


    @ApiOperation("银行机构列表")
    @RequestMapping("/bankAgent/list")
    public BaseResult bankAgentList(@RequestBody(required = false) String data){
        BankAgentListDto reqDto = RequestParamsManager.transformRequestParam(data, BankAgentListDto.class);

        return BaseResult.success(tagInfoService.bankAgentList(reqDto));
    }

    @ApiOperation("地区列表")
    @RequestMapping("/city/list")
    public BaseResult cityList(@RequestBody(required = false) String data){
        CityListDto reqDto = RequestParamsManager.transformRequestParam(data, CityListDto.class);

        return BaseResult.success(tagInfoService.cityList(reqDto));
    }


    @ApiOperation("所属行业列表")
    @RequestMapping("/merchantClass/list")
    public BaseResult merchantClassList(@RequestBody(required = false) String data) {
        MerchantClassListDto reqDto = RequestParamsManager.transformRequestParam(data, MerchantClassListDto.class);

        return BaseResult.success(tagInfoService.merchantList(reqDto));
    }


    @ApiOperation("获取所有标签分类")
    @RequestMapping("/getAllConditionClass")
    public BaseResult getAllConditionClass() {
        return BaseResult.success(conditionsNameService.getAllConditionClass());
    }


    @ApiOperation("查询标签提示列表")
    @RequestMapping("/listConditionsTips")
    public BaseResult listConditionsTips(@RequestBody(required = false) String data) {
        ListConditionsTipsDto reqDto = RequestParamsManager.transformRequestParam(data, ListConditionsTipsDto.class);
        return BaseResult.success(conditionsNameService.listConditionsTips(reqDto));
    }

    @ApiOperation("修改标签提示")
    @RequestMapping("/editConditionsTips")
    public BaseResult editConditionsTips(@RequestBody String data) {
        EditConditionsTipsDto reqDto = RequestParamsManager.transformRequestParam(data, EditConditionsTipsDto.class);
        return conditionsNameService.editConditionsTips(reqDto);
    }
    @ApiOperation("预估人数")
    @RequestMapping("/tagEstimate")
    public BaseResult tagEstimate(@RequestBody(required = false) String data){
        TagInfoDTO reqDto = RequestParamsManager.transformRequestParam(data, TagInfoDTO.class);
        return tagInfoService.tagEstimate(reqDto);
    }

}
